package com.jxwifi.cloud.quickclean.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.bean.ProductsBena;
import com.jxwifi.cloud.quickclean.bean.StrListBean;

import java.util.ArrayList;
import java.util.List;

public class PopKTListAdapter  extends BaseQuickAdapter<ProductsBena, BaseViewHolder> {

    public PopKTListAdapter(@LayoutRes int layoutResId, @Nullable List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ProductsBena item) {

        Glide.with(mContext).load(item.getImgUrl()).error(R.mipmap.icon_default_head).into((ImageView) helper.getView(R.id.img_pop_kit_items_images));
        helper.setText(R.id.tv_pop_kit_items_name, item.getName());
        if (!TextUtils.isEmpty(item.getJsonStr())){
            List<StrListBean> mList=new ArrayList<>();
            mList= JSON.parseArray(item.getJsonStr(), StrListBean.class);
            String Specifications="";
            for (int i=0;i<mList.size();i++){
                Specifications=Specifications+""+mList.get(i).getKey()+":"+mList.get(i).getValue();
            }
            helper.setText(R.id.tv_pop_kit_items_specifications,"规格："+ Specifications);
        }else{
            helper.setText(R.id.tv_pop_kit_items_specifications,"规格：暂无");
        }
        helper.setText(R.id.tv_pop_kit_items_price, "\u00A5" + String.valueOf(item.getValue()));
        helper.setText(R.id.tv_pop_kit_item_num,"x"+item.getNumber());
    }
}
